package socketmvc.core.codec;

import java.nio.ByteBuffer;
import java.util.Objects;

public abstract class AbstractCodec implements IPacketCodec {
    @Override
    public int getBufferReadableLength(ByteBuffer buffer){
        return buffer.limit() - buffer.position();
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(protocolVersion());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null){
            return false;
        }
        if (obj instanceof IPacketCodec codec){
            return  Objects.equals(protocolVersion(),codec.protocolVersion());
        }
        return false;
    }
}
